import { postRequest, getRequest } from '/@/lib/axios';
import useSchemaStore from "/@/store/SchemaStore";
import PlatRequest from "/@/plugins/request/type";


const request:any = {};

request.post = ( url:string , data:any , schema:string)=> {
    if (schema == undefined || schema === ""){
        schema = useSchemaStore().getSchema();
    }
    const params = new PlatRequest();
    params.setDatasource(schema);
    params.setParams(data);
    return new Promise((resolve, reject) => {
        postRequest(url, params).then((res) => resolve(res.data)).catch((res) => reject(res))
    })
}

request.postOriginal = ( url:string , data:any)=> {
    return new Promise((resolve, reject) => {
        postRequest(url, data).then((res) => resolve(res.data)).catch((res) => reject(res))
    })
}

request.get = ( url:string,params:String ) =>{
    return new Promise((resolve, reject) => {
        getRequest(url,params).then((res) => resolve(res.data)).catch((res) => reject(res))
    })
}




export default request;
